package com.fcscs.cservice.client.main.configuration.restaurant;

import java.util.ArrayList;
import java.util.List;

import com.extjs.gxt.ui.client.event.BaseEvent;
import com.extjs.gxt.ui.client.event.ButtonEvent;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
import com.extjs.gxt.ui.client.event.SelectionChangedListener;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.widget.HorizontalPanel;
import com.extjs.gxt.ui.client.widget.Label;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.VerticalPanel;
import com.extjs.gxt.ui.client.widget.form.ComboBox.TriggerAction;
import com.extjs.gxt.ui.client.widget.form.Field;
import com.extjs.gxt.ui.client.widget.form.FieldSet;
import com.extjs.gxt.ui.client.widget.form.Radio;
import com.extjs.gxt.ui.client.widget.form.RadioGroup;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.extjs.gxt.ui.client.widget.form.Validator;
import com.extjs.gxt.ui.client.widget.layout.ColumnData;
import com.extjs.gxt.ui.client.widget.layout.ColumnLayout;
import com.fcscs.core.gwt.common.CoreConstants;
import com.fcscs.core.gwt.common.CoreEnums.SubmitType;
import com.fcscs.core.gwt.common.FormSubmitListener;
import com.fcscs.core.gwt.common.ui.BaseFormDialog;
import com.fcscs.core.gwt.common.ui.FcsFields.EasyClearCombobox;
import com.fcscs.core.gwt.common.ui.FcsFields.FormButton;
import com.fcscs.core.gwt.common.ui.FcsFormPanel;
import com.fcscs.cservice.client.common.CServiceConstants;
import com.fcscs.cservice.client.common.model.configuration.restaurant.RestaurantModelData;
import com.fcscs.cservice.client.common.model.configuration.restaurant.SmokingAvailableGWTEnum;
import com.fcscs.cservice.client.common.model.configuration.restaurant.SmokingAvailableModelData;
import com.fcscs.cservice.client.common.model.restaurants.BookingStatusModelData;
import com.fcscs.cservice.common.CServiceCommonEnums.RestaurantConfigType;
import com.fcscs.cservice.domain.Restaurant;
import com.fcscs.cservice.domain.RestaurantConfig;
import com.fcscs.cservice.domain.model.RestaurantConfiguration;
import com.fcscs.share.gwt.common.ShareGWTConstants;

public class RestaurantConfigDialog extends BaseFormDialog<RestaurantConfiguration> implements FormSubmitListener<RestaurantConfiguration>{
	
	private static RestaurantConfigDialog INSTANCE;
	private MyFormPanel myFormPanel;
	private ListStore<SmokingAvailableModelData> smokingAvailableStore;
	private LayoutContainer container;
	private LayoutContainer container1;
	private FieldSet resFieldSet;
	private HorizontalPanel printerHp;
	private LayoutContainer container2;
	private Label serverNameLab;
	private HorizontalPanel econnectHp;
	private LayoutContainer container3;
	private ListStore<BookingStatusModelData> requestActionStore;
	private Label requestActionLab;
	private HorizontalPanel restaurantNameHp;
	private Label restaurantNameLab;
	private Label serviceCodeLab;
	private HorizontalPanel emailHp;
	private LayoutContainer container4;
	private Radio emailRadio;
	private Label addressLab;
	private HorizontalPanel cConnectHp;
	private LayoutContainer container5;
	private Radio cConnectRadio;
	private Label cRequestActionLab;
	private ListStore<BookingStatusModelData> cRequestActionStore;
	private Label cServiceCodeLab;
	private HorizontalPanel smokingOrNoSmokingHp;
	private TextField<String> serverNamefield;
	private EasyClearCombobox<BookingStatusModelData> requestActionCombox;
	private TextField<String> serviceCodefield;
	private TextField<String> addressfield;
	private EasyClearCombobox<BookingStatusModelData> cRequestActionCombox;
	private TextField<String> cServiceCodefield;
	private VerticalPanel vp;
	private FormButton saveBtn;
	private FormButton cancelBtn;
	private TextField<String> restaurantNameField;
	private EasyClearCombobox<SmokingAvailableModelData> smokingCombox;
	private Radio printerRadio ;
	private Radio econnectRadio;
	private FormSubmitListener<RestaurantConfiguration> listener;
	private RestaurantModelData currRestModel;
	
	public static RestaurantConfigDialog getInstance(FormSubmitListener<RestaurantConfiguration> fListener ,RestaurantConfig rc ,RestaurantModelData model) {
		INSTANCE = new RestaurantConfigDialog(rc, model);
		INSTANCE.listener = fListener;
		INSTANCE.setHeading(CServiceConstants.CSERVICE_CONSTANTS.restaurantConf());
		INSTANCE.currRestModel = model;
		return INSTANCE;
	}
	
	public RestaurantConfigDialog(RestaurantConfig rc ,RestaurantModelData model) {
		myFormPanel = new MyFormPanel(this,rc,model);
		add(myFormPanel);
		setSize(720, 330);
	}
	
	public class MyFormPanel extends FcsFormPanel<RestaurantConfiguration> {

		protected MyFormPanel(FormSubmitListener<RestaurantConfiguration> l,RestaurantConfig rc ,RestaurantModelData model) {
			super(l);
			setHeaderVisible(false);
			
			if (null == vp) {
				vp = new VerticalPanel();
				
				resConfigSet();
				
				saveBtn = new FormButton(CoreConstants.CORE_CONSTANTS.save());
				saveBtn.setId("RestaurantConfigPanel_saveBtn");
				saveBtn.setWidth(60);
				saveBtn.addSelectionListener(new SelectionListener<ButtonEvent>() {

					@Override
					public void componentSelected(ButtonEvent ce) {
						submit(SubmitType.DEFAULT);
					}
				});
				getButtonBar().add(saveBtn);
				
				cancelBtn = new FormButton(CoreConstants.CORE_CONSTANTS.cancel());
				cancelBtn.setId("RestaurantConfigPanel_cancelBtn");
				cancelBtn.setWidth(60);
				cancelBtn.addSelectionListener(new SelectionListener<ButtonEvent>() {

					@Override
					public void componentSelected(ButtonEvent ce) {
						RestaurantConfigDialog.this.hide();
					}
				});
				getButtonBar().add(cancelBtn);
				add(vp);
			}
	
			updateConfig(rc,model);
		}


		@Override
		protected void onShow() {
			super.onShow();
		}

		@Override
		public void setFocus() {
			
		}

		@Override
		public void updateForm(RestaurantConfiguration entity) {
			
		}

		@Override
		public void populateEntity(RestaurantConfiguration entity) {
			Restaurant restaurant = currRestModel.getEntity();
			restaurant.setPropertyId(currRestModel.getEntity().getPropertyId());
			restaurant.setOrgId(currRestModel.getEntity().getOrgId());
			restaurant.setName(restaurantNameField.getValue());
			restaurant.setSmoking(true);
			
			List<RestaurantConfig> restaurantConfigList= new ArrayList<RestaurantConfig>();
			RestaurantConfig restaurantConfig = new RestaurantConfig();
			restaurantConfig.setPropertyId(currRestModel.getEntity().getPropertyId());
			restaurantConfig.setRestaurantId(currRestModel.getEntity().getId());
			restaurantConfig.setOrgId(currRestModel.getEntity().getOrgId());
			
			if (printerRadio.getValue()) {
				restaurantConfig.setConfigTypeEnum(RestaurantConfigType.PRINTER);
				restaurantConfig.setNote1(serverNamefield.getValue());
			}
			if (econnectRadio.getValue()) {
				restaurantConfig.setConfigTypeEnum(RestaurantConfigType.E_CONNECT);
				restaurantConfig.setNote2(serviceCodefield.getValue());
			}
			if (emailRadio.getValue()) {
				restaurantConfig.setConfigTypeEnum(RestaurantConfigType.EMAIL);
				restaurantConfig.setNote2(addressfield.getValue());
			}
			if (cConnectRadio.getValue()) {
				restaurantConfig.setConfigTypeEnum(RestaurantConfigType.C_CONNECT);
				restaurantConfig.setNote2(cServiceCodefield.getValue());
			}
			restaurantConfigList.add(restaurantConfig);
			
			entity.setRestaurant(restaurant);
			entity.setRestConfigDetail(restaurantConfigList);
		}
	}
	
	public void resConfigSet(){
		resFieldSet = new FieldSet();
		resFieldSet.setBorders(false);
		resFieldSet.setId("RestaurantConfigDialog_resFieldSet");
		vp.add(resFieldSet);
		
		final RadioGroup group = new RadioGroup();
		group.setId("RestaurantConfigPanel_group");
		group.addListener(Events.Change, new Listener<BaseEvent>() {

			@Override
			public void handleEvent(BaseEvent be) {

				// change Radio
				if ((RestaurantConfigType.PRINTER.toString())
						.equals(group.getValue().getFieldLabel())) {
					serverNamefield.setEnabled(true);
					requestActionCombox.setEnabled(false);
					serviceCodefield.setEnabled(false);
					addressfield.setEnabled(false);
					cRequestActionCombox.setEnabled(false);
					cServiceCodefield.setEnabled(false);
					// requestActionCombox.clearSelections();
					// serviceCodefield.clear();
					// addressfield.clear();
					// cRequestActionCombox.clearSelections();
					// cServiceCodefield.clear();
				}
				if ((RestaurantConfigType.E_CONNECT.toString()).equals(group.getValue()
						.getFieldLabel())) {
					serverNamefield.setEnabled(false);
					requestActionCombox.setEnabled(true);
					serviceCodefield.setEnabled(true);
					addressfield.setEnabled(false);
					cRequestActionCombox.setEnabled(false);
					cServiceCodefield.setEnabled(false);
					// serverNamefield.clear();
					// addressfield.clear();
					// cRequestActionCombox.clearSelections();
					// cServiceCodefield.clear();
				}
				if ((RestaurantConfigType.EMAIL.toString()).equals(group.getValue().getFieldLabel())) {
					serverNamefield.setEnabled(false);
					requestActionCombox.setEnabled(false);
					serviceCodefield.setEnabled(false);
					addressfield.setEnabled(true);
					cRequestActionCombox.setEnabled(false);
					cServiceCodefield.setEnabled(false);
					// serverNamefield.clear();
					// requestActionCombox.clearSelections();
					// serviceCodefield.clear();
					// cRequestActionCombox.clearSelections();
					// cServiceCodefield.clear();
				}
				if ((RestaurantConfigType.C_CONNECT.toString()).equals(group.getValue()
						.getFieldLabel())) {
					serverNamefield.setEnabled(false);
					requestActionCombox.setEnabled(false);
					serviceCodefield.setEnabled(false);
					addressfield.setEnabled(false);
					cRequestActionCombox.setEnabled(true);
					cServiceCodefield.setEnabled(true);
					// serviceCodefield.clear();
					// requestActionCombox.clearSelections();
					// serviceCodefield.clear();
					// addressfield.clear();
				}
			
			}});

		// Retaurant Name
		restaurantNameHp = new HorizontalPanel();
		restaurantNameHp.setSpacing(5);
		restaurantNameHp.setId("RestaurantConfigPanel_restaurantNameHp");
		resFieldSet.add(restaurantNameHp);
		
		container1 = new LayoutContainer();
		container1.setLayout(new ColumnLayout());
		restaurantNameHp.add(container1);
		restaurantNameLab = new Label(CoreConstants.CORE_MESSAGES.operation(
				CServiceConstants.CSERVICE_CONSTANTS.restaurant(), CoreConstants.CORE_CONSTANTS.name()
						+ CServiceConstants.FIELD_SEP));
		restaurantNameLab.setId("RestaurantConfigPanel_serverNameLab");
		container1.add(restaurantNameLab, new ColumnData(200));
		
		restaurantNameField = new TextField<String>();
		restaurantNameField.setId("RestaurantConfigPanel_restaurantNameField");
		container1.add(restaurantNameField, new ColumnData(200));
		restaurantNameField.setAllowBlank(false);
		restaurantNameHp.add(container1);
		restaurantNameField.addListener(Events.OnBlur, new Listener<BaseEvent>() {

			@Override
			public void handleEvent(BaseEvent be) {
//				if (null != restaurantNameField.getValue()) {
//					restConList.get(i).getRestaurant().setName(restaurantNameField.getValue());
//				}
			}
		});

		// smoking
		smokingOrNoSmokingHp = new HorizontalPanel();
		smokingOrNoSmokingHp.setSpacing(5);
		smokingOrNoSmokingHp.setId("RestaurantConfigPanel_smokingOrNoSmokingHp");
		resFieldSet.add(smokingOrNoSmokingHp);

		container = new LayoutContainer();
		container.setLayout(new ColumnLayout());
		smokingOrNoSmokingHp.add(container);

		Label smokingOrNoSmokingLab = new Label(CServiceConstants.CSERVICE_CONSTANTS.smoking()
				+ CServiceConstants.FIELD_SEP);
		smokingOrNoSmokingLab.setId("RestaurantConfigPanel_smokingOrNoSmokingLab");
		container.add(smokingOrNoSmokingLab, new ColumnData(200));

		smokingCombox = new EasyClearCombobox<SmokingAvailableModelData>();
		smokingCombox.setTriggerAction(TriggerAction.ALL);
		smokingCombox.setForceSelection(true);
		smokingCombox.setDisplayField(CoreConstants.FULLTNAME);
		smokingAvailableStore = new ListStore<SmokingAvailableModelData>();
		for (SmokingAvailableGWTEnum se : SmokingAvailableGWTEnum.values()) {
			smokingAvailableStore.add(new SmokingAvailableModelData(se));
		}
		smokingCombox.setStore(smokingAvailableStore);
		smokingCombox.setId("RestaurantConfigPanel_smokingOrNoSmokingCombox");
		container.add(smokingCombox, new ColumnData(200));
		smokingCombox.addSelectionChangedListener(new SelectionChangedListener<SmokingAvailableModelData>() {

			@Override
			public void selectionChanged(SelectionChangedEvent<SmokingAvailableModelData> se) {
				if (null != smokingCombox.getValue()) {
//					System.out.println("===RawValue=======" + smokingCombox.getRawValue());
//					if (smokingCombox.getValue().equals(SmokingAvailableGWTEnum.YES.toString())) {
//						restConList.get(i).getRestaurant().setSmoking(true);
//					} else if (smokingCombox.getRawValue().toLowerCase()
//							.equals(SmokingAvailableGWTEnum.NO.toString())) {
//						restConList.get(i).getRestaurant().setSmoking(false);
//					}
				}
			}
		});

		// printer
		printerHp = new HorizontalPanel();
		printerHp.setSpacing(5);
		printerHp.setId("RestaurantConfigPanel_printerHp");
		resFieldSet.add(printerHp);
		container2 = new LayoutContainer();
		container2.setLayout(new ColumnLayout());
		printerHp.add(container2);
		printerRadio = new Radio();
		printerRadio.setId("RestaurantConfigPanel_printerRadio");
		printerRadio.setBoxLabel(ShareGWTConstants.SHARE_GWT_CONSTANTS.printer()
				+ CServiceConstants.FIELD_SEP);

		// Notice:Group Radio will get the fieldLabel's value.
		printerRadio.setFieldLabel(RestaurantConfigType.PRINTER.toString());
		container2.add(printerRadio, new ColumnData(100));
		group.add(printerRadio);
		serverNameLab = new Label(CServiceConstants.CSERVICE_CONSTANTS.serverName()
				+ CServiceConstants.FIELD_SEP);
		serverNameLab.setId("RestaurantConfigPanel_serverNameLab");
		container2.add(serverNameLab, new ColumnData(100));
		
		serverNamefield = new TextField<String>();
		serverNamefield.setEnabled(false);
		serverNamefield.setId("RestaurantConfigPanel_serverNamefield");
		container2.add(serverNamefield, new ColumnData(200));
		serverNamefield.addListener(Events.OnBlur, new Listener<BaseEvent>() {

			@Override
			public void handleEvent(BaseEvent be) {
//
//				if (!(RestaurantConfigType.PRINTER.toString()).equals(restConList.get(i)
//						.getRestConfigDetail().get(0).getConfigType())) {
//					return;
//				}
//				if (null != serverNamefield.getValue()) {
//					restConList.get(i).getRestConfigDetail().get(0).setNote1(serverNamefield.getValue());
//					restConList.get(i).getRestConfigDetail().get(0).setNote2(null);
//					restConList.get(i).getRestConfigDetail().get(0).setNote3(null);
//				}
			}
		});
		
		// e-connect
		econnectHp = new HorizontalPanel();
		econnectHp.setSpacing(5);
		econnectHp.setId("RestaurantConfigPanel_econnectHp");
		resFieldSet.add(econnectHp);
		
		container3 = new LayoutContainer();
		container3.setLayout(new ColumnLayout());
		econnectHp.add(container3);
		
		econnectRadio = new Radio();
		econnectRadio.setId("RestaurantConfigPanel_econnectRadio");
		econnectRadio.setBoxLabel(CServiceConstants.CSERVICE_CONSTANTS.eConnect()
				+ CServiceConstants.FIELD_SEP);
		econnectRadio.setFieldLabel(RestaurantConfigType.E_CONNECT.toString());
		container3.add(econnectRadio, new ColumnData(100));
		group.add(econnectRadio);
		
		requestActionLab = new Label(CServiceConstants.CSERVICE_CONSTANTS.requestAction()
				+ CServiceConstants.FIELD_SEP);
		requestActionLab.setId("RestaurantConfigPanel_requestActionLab");
		container3.add(requestActionLab, new ColumnData(100));
	
		HorizontalPanel hp1 = new HorizontalPanel();
		hp1.setId("RestaurantConfigPanel_hp1");
		
		requestActionCombox = new EasyClearCombobox<BookingStatusModelData>();
		requestActionCombox.setId("RestaurantConfigPanel_requestActionCombox");
		requestActionStore = new ListStore<BookingStatusModelData>();
		requestActionCombox.setWidth(150);
		requestActionCombox.setEnabled(false);
		requestActionCombox.setTriggerAction(TriggerAction.ALL);
		requestActionCombox.setForceSelection(true);
		requestActionCombox.setStore(requestActionStore);
		hp1.add(requestActionCombox);
		container3.add(hp1, new ColumnData(200));

		serviceCodeLab = new Label(CServiceConstants.CSERVICE_CONSTANTS.serviceCode()
				+ CServiceConstants.FIELD_SEP);
		serviceCodeLab.setId("RestaurantConfigPanel_serviceCodeLab");
		container3.add(serviceCodeLab, new ColumnData(100));
		
		serviceCodefield = new TextField<String>();
		serviceCodefield.setId("RestaurantConfigPanel_serviceCodefield");
		serviceCodefield.setEnabled(false);
		container3.add(serviceCodefield, new ColumnData(150));
		serviceCodefield.addListener(Events.OnBlur, new Listener<BaseEvent>() {

			@Override
			public void handleEvent(BaseEvent be) {
				RestaurantConfiguration resc = new RestaurantConfiguration();
				Restaurant restaurant = new Restaurant();
				restaurant.setName(restaurantNameField.getValue());
//				restaurant.setSmoking();
				List<RestaurantConfig> restaurantConfigList = new ArrayList<RestaurantConfig>();
				RestaurantConfig restaurantConfig = new RestaurantConfig();
				if (printerRadio.getValue()) {
					restaurantConfig.setNote1(serverNamefield.getValue());
				}
				if (econnectRadio.getValue()) {
//					restaurantConfig.setNote1(requestActionCombox.getValue().toString());
					restaurantConfig.setNote2(serviceCodefield.getValue());
				}
				if (emailRadio.getValue()) {
					restaurantConfig.setNote1(addressfield.getValue());
				}
				if (cConnectRadio.getValue()) {
					restaurantConfig.setNote2(cServiceCodefield.getValue());
				}
				restaurantConfigList.add(restaurantConfig);
				resc.setRestaurant(restaurant);
				resc.setRestConfigDetail(restaurantConfigList);
			}
		});
		
		// email
		emailHp = new HorizontalPanel();
		emailHp.setSpacing(5);
		emailHp.setId("RestaurantConfigPanel_emailHp");
		resFieldSet.add(emailHp);
		
		container4 = new LayoutContainer();
		container4.setLayout(new ColumnLayout());
		emailHp.add(container4);
		
		emailRadio = new Radio();
		emailRadio.setId("RestaurantConfigPanel_emailRadio");
		emailRadio.setBoxLabel(CoreConstants.CORE_CONSTANTS.email() + CServiceConstants.FIELD_SEP);
		emailRadio.setFieldLabel(RestaurantConfigType.EMAIL.toString());
		container4.add(emailRadio, new ColumnData(100));
		group.add(emailRadio);
		
		addressLab = new Label(ShareGWTConstants.SHARE_GWT_CONSTANTS.address() + CServiceConstants.FIELD_SEP);
		addressLab.setId("RestaurantConfigPanel_addressLab");
		container4.add(addressLab, new ColumnData(100));
		
		addressfield = new TextField<String>();
		addressfield.setId("RestaurantConfigPanel_addressfield");
		addressfield.setEnabled(false);
		container4.add(addressfield, new ColumnData(400));
		addressfield.addListener(Events.OnBlur, new Listener<BaseEvent>() {

			@Override
			public void handleEvent(BaseEvent be) {
//				if (!(RestaurantConfigType.EMAIL.toString()).equals(restConList.get(i).getRestConfigDetail()
//						.get(0).getConfigType())) {
//					return;
//				}
//				if (null != addressfield.getValue()) {
//					restConList.get(i).getRestConfigDetail().get(0).setNote1(addressfield.getValue());
//					restConList.get(i).getRestConfigDetail().get(0).setNote2(null);
//					restConList.get(i).getRestConfigDetail().get(0).setNote3(null);
//				}
			}
		});
		final String emailReg = "\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*";
		addressfield.setValidator(new Validator() {
			@Override
			public String validate(Field<?> field, String value) {
				if (!value.toUpperCase().matches(emailReg)) {
					return ShareGWTConstants.SHARE_GWT_CONSTANTS.emailErro();
				} else if (value.length() > 50) {
					return ShareGWTConstants.SHARE_GWT_MESSAGES.outOfLength(
							CoreConstants.CORE_CONSTANTS.email(), 50);
				}
				return null;
			}
		});
		
		// c-connect
		cConnectHp = new HorizontalPanel();
		cConnectHp.setSpacing(5);
		cConnectHp.setId("RestaurantConfigPanel_cConnectHp");
		resFieldSet.add(cConnectHp);
		container5 = new LayoutContainer();
		container5.setLayout(new ColumnLayout());
		cConnectHp.add(container5);
		
		cConnectRadio = new Radio();
		cConnectRadio.setId("RestaurantConfigPanel_cConnectRadio");
		cConnectRadio.setBoxLabel(CServiceConstants.CSERVICE_CONSTANTS.cConnect()
				+ CServiceConstants.FIELD_SEP);
		cConnectRadio.setFieldLabel(RestaurantConfigType.C_CONNECT.toString());
		container5.add(cConnectRadio, new ColumnData(100));
		group.add(cConnectRadio);
		
		cRequestActionLab = new Label(CServiceConstants.CSERVICE_CONSTANTS.requestAction()
				+ CServiceConstants.FIELD_SEP);
		cRequestActionLab.setId("RestaurantConfigPanel_cRequestActionLab");
		container5.add(cRequestActionLab, new ColumnData(100));
		HorizontalPanel hp2 = new HorizontalPanel();
		hp2.setId("RestaurantConfigPanel_hp2");
		
		cRequestActionCombox = new EasyClearCombobox<BookingStatusModelData>();
		cRequestActionCombox.setId("RestaurantConfigPanel_cRequestActionCombox");
		cRequestActionCombox.setEnabled(false);
		cRequestActionCombox.setTriggerAction(TriggerAction.ALL);
		cRequestActionCombox.setForceSelection(true);
		cRequestActionStore = new ListStore<BookingStatusModelData>();
		cRequestActionCombox.setWidth(150);
		cRequestActionCombox.setStore(cRequestActionStore);
		hp2.add(cRequestActionCombox);
		
		
		container5.add(hp2, new ColumnData(200));
		cServiceCodeLab = new Label(CServiceConstants.CSERVICE_CONSTANTS.serviceCode()
				+ CServiceConstants.FIELD_SEP);
		cServiceCodeLab.setId("RestaurantConfigPanel_cServiceCodeLab");
		container5.add(cServiceCodeLab, new ColumnData(100));
		
		cServiceCodefield = new TextField<String>();
		cServiceCodefield.setId("RestaurantConfigPanel_cServiceCodefield");
		cServiceCodefield.setEnabled(false);
		container5.add(cServiceCodefield, new ColumnData(150));
		cServiceCodefield.addListener(Events.OnBlur, new Listener<BaseEvent>() {

			@Override
			public void handleEvent(BaseEvent be) {
//				if (!(RestaurantConfigType.C_CONNECT.toString()).equals(restConList.get(i)
//						.getRestConfigDetail().get(0).getConfigType())) {
//					return;
//				}
//				if (null != cServiceCodefield.getValue()) {
//					restConList.get(i).getRestConfigDetail().get(0).setNote2(cServiceCodefield.getValue());
//					restConList.get(i).getRestConfigDetail().get(0).setNote3(null);
//				}
			}
		});

	}
	
	
	public void updateConfig(RestaurantConfig rc ,RestaurantModelData model) {
		restaurantNameField.setValue(model.getEntity().getName());
		if (model.getEntity().getSmoking()) {
			smokingCombox.setValue(new SmokingAvailableModelData(SmokingAvailableGWTEnum.YES));
		} else {
			smokingCombox.setValue(new SmokingAvailableModelData(SmokingAvailableGWTEnum.NO));
		}
		if (null != rc) {
			if ((RestaurantConfigType.PRINTER.toString()).equals(rc.getConfigType())) {
				printerRadio.setValue(true);
				if (null != rc.getNote1()) {
					serverNamefield.setValue(rc.getNote1());
				}
			}
			if ((RestaurantConfigType.E_CONNECT.toString()).equals(rc.getConfigType())) {
				econnectRadio.setValue(true);
				if (null != rc.getNote1()) {
					// requestActionCombox.setvalue
				}
				if (null != rc.getNote2()) {
					serviceCodefield.setValue(rc.getNote2());
				}
				
			}
			if ((RestaurantConfigType.EMAIL.toString()).equals(rc.getConfigType())) {
				emailRadio.setValue(true);
				if (null != rc.getNote1()) {
					addressfield.setValue(rc.getNote1());
				}
			}
			if ((RestaurantConfigType.C_CONNECT.toString()).equals(rc.getConfigType())) {
				cConnectRadio.setValue(true);
				if (null != rc.getNote2()) {
					cServiceCodefield.setValue(rc.getNote2());
				}
			}
		}
	}
	
	@Override
	protected FcsFormPanel<RestaurantConfiguration> getFormPanel() {
		return myFormPanel;
	}

	@Override
	public void formSubmitCallBack(FcsFormPanel<RestaurantConfiguration> form, SubmitType submitType) {
		if (null != listener) {
			listener.formSubmitCallBack(form, submitType);
		}
	}
}
